import { normalize, schema } from 'normalizr';

/**
 * 对返回结果进行扁平化，将json转成数据库的范式，避免过forEach循环查找数据
 */
export default {
    /**
     * 系统配置文件
     * @param {*} config 
     */
    system(inputConfig) {
        let projects = new schema.Entity('projects', {}, { idAttribute: 'alias' });
        let domains = new schema.Entity('domains', {}, { idAttribute: 'alias' });
        projects = new schema.Array(projects);
        domains = new schema.Array(domains);

        const config = {
            projects,
            domains,
        };

        const outputConfig = normalize(inputConfig, config);

        return outputConfig;
    },
}